package com.huynhchihieu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.huynhchihieu.domain.Domainuser;
import com.huynhchihieu.domain.Role;
import com.huynhchihieu.service.RoleService;
import com.huynhchihieu.service.UserService;

@Controller
public class UserController {
	
	@Autowired
	UserService userService;
	
	@Autowired
	RoleService roleService;
	
	
	@RequestMapping("/user")
	public String user(Model model){
		List<Role> roles = roleService.getRoles();
		model.addAttribute("roles", roles);
		model.addAttribute("user", new Domainuser());
		return "register";
	}
	
	@RequestMapping("/createuser")
	public String createUser(Model model, @RequestParam("roleId") int roleId, @ModelAttribute Domainuser user){
		//insert domain_user
		userService.createUser(user, roleId);
		// insert user_role then get user_role entity to next insert domainuser
		
		return null;
	}
	
	
}
